enum Side { Long, Short };
enum OrderTypes { Market, Limit, StopLimit };

ref class OrderData;
delegate void OrderStatusChangedDel(int orderIndex, OrderData ^orderData, bool firstTimeThatGotQuantity);
ref class Orders
{
public:
	event OrderStatusChangedDel ^OrderStatusChanged;
	void FireOrderStatusChangedEvent(int orderIndex, OrderData ^orderData, bool firstTimeThatGotQuantity);

	Symbol ^Owner() { return owner; }

	int NewOrder(int quantity, Side side, OrderTypes orderType, float stopPrice, float limitPrice, bool multiplyBySubAccounts);
	void UpdateOrder(int orderIndex, int quantity, Side side, OrderTypes orderType, float stopPrice, float limitPrice, bool multiplyBySubAccounts);
	void CancelLimitsAndSellQuantity();
	void CancelLimitsAndSellQuantity(float limitPrice);
	int AllFilledQuantity();
	OrderData^ operator[](int index);
	Orders(Symbol ^owner);

protected:
	Symbol ^owner;
	List<OrderData^> ^orders;
};

// ****************************************************************************************************

ref class OrderData
{
public:
	int FilledQuantity() { return (side == Long ? filledQuantity : filledQuantity * -1); }
	int RemainingQuantity() { return (side == Long ? remainingQuantity : remainingQuantity * -1);; }
	int TotalQuantity() { return (side == Long ? totalQuantity : totalQuantity * -1);; }
	Side Side_() { return side; }
	OrderTypes OrderType() { return orderType; }
	float StopPrice() { return stopPrice; }
	float LimitPrice() { return limitPrice; }
	String ^Status() { return status; }
	int OrderID() { return orderID; }

	void CancelLimit();
	OrderData(Orders ^owner, int orderIndex, int orderID, int totalQuantity, Side side, OrderTypes orderType, float stopPrice, float limitPrice);

protected:
	Orders ^owner;
	int orderIndex;
	int orderID;
	int filledQuantity;
	int remainingQuantity;
	int totalQuantity;
	Side side;
	OrderTypes orderType;
	float stopPrice;
	float limitPrice;
	String ^status;

	void getOrderStatus(System::Object ^sender, AxTWSLib::_DTwsEvents_orderStatusEvent ^e);
};